﻿using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using LibHuman;
namespace Human
{
	/// <summary>
	/// Summary description for frmChucv.
	/// </summary>
	public class frmChucv : System.Windows.Forms.Form
	{
		/// <summary>
		/// Required designer variable.
		/// </summary>
		/// 
		private AccessData mDB=new AccessData();
        Language lan = new Language();
		private DataSet ds=new DataSet();
        string m_user = "";
        int flag=0;
		private System.Windows.Forms.DataGrid dgrDanhMuc1;
		private System.Windows.Forms.TextBox txtTen;
		private System.Windows.Forms.Label label2;
		private System.Windows.Forms.TextBox txtMa;
        private System.Windows.Forms.Label label1;
        private Label label3;
        private TextBox txtsott;
        private TextBox txttenvt;
        private Label label4;
        private Label label5;
        private TextBox txtheso;
        private Label label6;
        private CheckBox checklanhdao;
        private GroupBox groupBox1;
        private Button btn_them;
        private Button btn_sua;
        private Button btn_luu;
        private Button btn_boqua;
        private Button btn_xoa;
        private Button btn_thoat;
		private System.ComponentModel.Container components = null;

		public frmChucv()
		{
			InitializeComponent();
            lan.Read_Language_to_Xml(this.Name.ToString(), this);
            lan.Changelanguage_to_English(this.Name.ToString(), this);
		}

		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if(components != null)
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
            System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(frmChucv));
            this.dgrDanhMuc1 = new System.Windows.Forms.DataGrid();
            this.txtTen = new System.Windows.Forms.TextBox();
            this.label2 = new System.Windows.Forms.Label();
            this.txtMa = new System.Windows.Forms.TextBox();
            this.label1 = new System.Windows.Forms.Label();
            this.label3 = new System.Windows.Forms.Label();
            this.txtsott = new System.Windows.Forms.TextBox();
            this.txttenvt = new System.Windows.Forms.TextBox();
            this.label4 = new System.Windows.Forms.Label();
            this.label5 = new System.Windows.Forms.Label();
            this.txtheso = new System.Windows.Forms.TextBox();
            this.label6 = new System.Windows.Forms.Label();
            this.checklanhdao = new System.Windows.Forms.CheckBox();
            this.groupBox1 = new System.Windows.Forms.GroupBox();
            this.btn_thoat = new System.Windows.Forms.Button();
            this.btn_xoa = new System.Windows.Forms.Button();
            this.btn_boqua = new System.Windows.Forms.Button();
            this.btn_luu = new System.Windows.Forms.Button();
            this.btn_sua = new System.Windows.Forms.Button();
            this.btn_them = new System.Windows.Forms.Button();
            ((System.ComponentModel.ISupportInitialize)(this.dgrDanhMuc1)).BeginInit();
            this.groupBox1.SuspendLayout();
            this.SuspendLayout();
            // 
            // dgrDanhMuc1
            // 
            this.dgrDanhMuc1.AlternatingBackColor = System.Drawing.Color.Lavender;
            this.dgrDanhMuc1.BackColor = System.Drawing.Color.WhiteSmoke;
            this.dgrDanhMuc1.BackgroundColor = System.Drawing.SystemColors.Control;
            this.dgrDanhMuc1.BorderStyle = System.Windows.Forms.BorderStyle.None;
            this.dgrDanhMuc1.CaptionBackColor = System.Drawing.Color.LightSteelBlue;
            this.dgrDanhMuc1.CaptionForeColor = System.Drawing.Color.MidnightBlue;
            this.dgrDanhMuc1.CaptionText = "Danh mục chức vụ";
            this.dgrDanhMuc1.CaptionVisible = false;
            this.dgrDanhMuc1.DataMember = "";
            this.dgrDanhMuc1.FlatMode = true;
            this.dgrDanhMuc1.Font = new System.Drawing.Font("Tahoma", 8F);
            this.dgrDanhMuc1.ForeColor = System.Drawing.Color.MidnightBlue;
            this.dgrDanhMuc1.GridLineColor = System.Drawing.Color.Gainsboro;
            this.dgrDanhMuc1.GridLineStyle = System.Windows.Forms.DataGridLineStyle.None;
            this.dgrDanhMuc1.HeaderBackColor = System.Drawing.Color.MidnightBlue;
            this.dgrDanhMuc1.HeaderFont = new System.Drawing.Font("Tahoma", 8F, System.Drawing.FontStyle.Bold);
            this.dgrDanhMuc1.HeaderForeColor = System.Drawing.Color.WhiteSmoke;
            this.dgrDanhMuc1.LinkColor = System.Drawing.Color.Teal;
            this.dgrDanhMuc1.Location = new System.Drawing.Point(8, 8);
            this.dgrDanhMuc1.Name = "dgrDanhMuc1";
            this.dgrDanhMuc1.ParentRowsBackColor = System.Drawing.Color.Gainsboro;
            this.dgrDanhMuc1.ParentRowsForeColor = System.Drawing.Color.MidnightBlue;
            this.dgrDanhMuc1.RowHeaderWidth = 10;
            this.dgrDanhMuc1.SelectionBackColor = System.Drawing.Color.CadetBlue;
            this.dgrDanhMuc1.SelectionForeColor = System.Drawing.Color.WhiteSmoke;
            this.dgrDanhMuc1.Size = new System.Drawing.Size(487, 304);
            this.dgrDanhMuc1.TabIndex = 12;
            this.dgrDanhMuc1.CurrentCellChanged += new System.EventHandler(this.dgrDanhMuc1_CurrentCellChanged);
            // 
            // txtTen
            // 
            this.txtTen.BackColor = System.Drawing.Color.White;
            this.txtTen.ForeColor = System.Drawing.Color.DarkBlue;
            this.txtTen.Location = new System.Drawing.Point(54, 338);
            this.txtTen.MaxLength = 50;
            this.txtTen.Name = "txtTen";
            this.txtTen.Size = new System.Drawing.Size(163, 20);
            this.txtTen.TabIndex = 1;
            this.txtTen.KeyDown += new System.Windows.Forms.KeyEventHandler(this.txtTen_KeyDown);
            // 
            // label2
            // 
            this.label2.BackColor = System.Drawing.SystemColors.Control;
            this.label2.ForeColor = System.Drawing.Color.DarkBlue;
            this.label2.Location = new System.Drawing.Point(51, 322);
            this.label2.Name = "label2";
            this.label2.Size = new System.Drawing.Size(74, 13);
            this.label2.TabIndex = 115;
            this.label2.Text = "Tên chức vụ :";
            this.label2.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            // 
            // txtMa
            // 
            this.txtMa.BackColor = System.Drawing.Color.White;
            this.txtMa.Enabled = false;
            this.txtMa.ForeColor = System.Drawing.Color.DarkBlue;
            this.txtMa.Location = new System.Drawing.Point(10, 338);
            this.txtMa.Name = "txtMa";
            this.txtMa.Size = new System.Drawing.Size(40, 20);
            this.txtMa.TabIndex = 0;
            this.txtMa.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
            this.txtMa.KeyDown += new System.Windows.Forms.KeyEventHandler(this.txtMa_KeyDown);
            // 
            // label1
            // 
            this.label1.BackColor = System.Drawing.SystemColors.Control;
            this.label1.ForeColor = System.Drawing.Color.DarkBlue;
            this.label1.Location = new System.Drawing.Point(7, 322);
            this.label1.Name = "label1";
            this.label1.Size = new System.Drawing.Size(43, 13);
            this.label1.TabIndex = 113;
            this.label1.Text = "Mã cv :";
            this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            // 
            // label3
            // 
            this.label3.ForeColor = System.Drawing.Color.DarkBlue;
            this.label3.Location = new System.Drawing.Point(313, 322);
            this.label3.Name = "label3";
            this.label3.Size = new System.Drawing.Size(53, 13);
            this.label3.TabIndex = 117;
            this.label3.Text = "Số thứ tự:";
            this.label3.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            // 
            // txtsott
            // 
            this.txtsott.BackColor = System.Drawing.SystemColors.Control;
            this.txtsott.Enabled = false;
            this.txtsott.Location = new System.Drawing.Point(316, 338);
            this.txtsott.Name = "txtsott";
            this.txtsott.Size = new System.Drawing.Size(50, 20);
            this.txtsott.TabIndex = 3;
            this.txtsott.KeyDown += new System.Windows.Forms.KeyEventHandler(this.txtsott_KeyDown);
            // 
            // txttenvt
            // 
            this.txttenvt.BackColor = System.Drawing.SystemColors.Control;
            this.txttenvt.Enabled = false;
            this.txttenvt.Location = new System.Drawing.Point(224, 338);
            this.txttenvt.Name = "txttenvt";
            this.txttenvt.Size = new System.Drawing.Size(86, 20);
            this.txttenvt.TabIndex = 2;
            this.txttenvt.KeyDown += new System.Windows.Forms.KeyEventHandler(this.txttenvt_KeyDown);
            // 
            // label4
            // 
            this.label4.BackColor = System.Drawing.SystemColors.Control;
            this.label4.ForeColor = System.Drawing.Color.DarkBlue;
            this.label4.Location = new System.Drawing.Point(221, 322);
            this.label4.Name = "label4";
            this.label4.Size = new System.Drawing.Size(67, 13);
            this.label4.TabIndex = 119;
            this.label4.Text = "Tên viết tắt :";
            this.label4.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            // 
            // label5
            // 
            this.label5.ForeColor = System.Drawing.Color.DarkBlue;
            this.label5.Location = new System.Drawing.Point(369, 322);
            this.label5.Name = "label5";
            this.label5.Size = new System.Drawing.Size(41, 13);
            this.label5.TabIndex = 117;
            this.label5.Text = "Hệ số :";
            this.label5.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            // 
            // txtheso
            // 
            this.txtheso.BackColor = System.Drawing.SystemColors.Control;
            this.txtheso.Enabled = false;
            this.txtheso.Location = new System.Drawing.Point(372, 338);
            this.txtheso.MaxLength = 13;
            this.txtheso.Name = "txtheso";
            this.txtheso.Size = new System.Drawing.Size(63, 20);
            this.txtheso.TabIndex = 4;
            this.txtheso.KeyDown += new System.Windows.Forms.KeyEventHandler(this.txtheso_KeyDown);
            // 
            // label6
            // 
            this.label6.ForeColor = System.Drawing.Color.DarkBlue;
            this.label6.Location = new System.Drawing.Point(442, 322);
            this.label6.Name = "label6";
            this.label6.Size = new System.Drawing.Size(53, 13);
            this.label6.TabIndex = 120;
            this.label6.Text = "Lãnh đạo";
            this.label6.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            // 
            // checklanhdao
            // 
            this.checklanhdao.AutoSize = true;
            this.checklanhdao.BackColor = System.Drawing.SystemColors.ActiveCaptionText;
            this.checklanhdao.Enabled = false;
            this.checklanhdao.Location = new System.Drawing.Point(445, 343);
            this.checklanhdao.Margin = new System.Windows.Forms.Padding(0);
            this.checklanhdao.Name = "checklanhdao";
            this.checklanhdao.Size = new System.Drawing.Size(15, 14);
            this.checklanhdao.TabIndex = 5;
            this.checklanhdao.UseVisualStyleBackColor = false;
            this.checklanhdao.KeyDown += new System.Windows.Forms.KeyEventHandler(this.checklanhdao_KeyDown);
            // 
            // groupBox1
            // 
            this.groupBox1.Controls.Add(this.btn_thoat);
            this.groupBox1.Controls.Add(this.btn_xoa);
            this.groupBox1.Controls.Add(this.btn_boqua);
            this.groupBox1.Controls.Add(this.btn_luu);
            this.groupBox1.Controls.Add(this.btn_sua);
            this.groupBox1.Controls.Add(this.btn_them);
            this.groupBox1.Location = new System.Drawing.Point(10, 364);
            this.groupBox1.Name = "groupBox1";
            this.groupBox1.Size = new System.Drawing.Size(476, 51);
            this.groupBox1.TabIndex = 121;
            this.groupBox1.TabStop = false;
            // 
            // btn_thoat
            // 
            this.btn_thoat.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.btn_thoat.ForeColor = System.Drawing.Color.DarkBlue;
            this.btn_thoat.Image = global::Human.Properties.Resources.close_r;
            this.btn_thoat.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
            this.btn_thoat.Location = new System.Drawing.Point(374, 20);
            this.btn_thoat.Name = "btn_thoat";
            this.btn_thoat.Size = new System.Drawing.Size(60, 28);
            this.btn_thoat.TabIndex = 12;
            this.btn_thoat.Text = "&Thoát";
            this.btn_thoat.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            this.btn_thoat.UseVisualStyleBackColor = true;
            this.btn_thoat.Click += new System.EventHandler(this.btn_thoat_Click);
            // 
            // btn_xoa
            // 
            this.btn_xoa.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.btn_xoa.ForeColor = System.Drawing.Color.DarkBlue;
            this.btn_xoa.Image = global::Human.Properties.Resources.delete_enabled;
            this.btn_xoa.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
            this.btn_xoa.Location = new System.Drawing.Point(308, 20);
            this.btn_xoa.Name = "btn_xoa";
            this.btn_xoa.Size = new System.Drawing.Size(60, 28);
            this.btn_xoa.TabIndex = 11;
            this.btn_xoa.Text = "&Xóa";
            this.btn_xoa.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            this.btn_xoa.UseVisualStyleBackColor = true;
            this.btn_xoa.Click += new System.EventHandler(this.btn_xoa_Click);
            // 
            // btn_boqua
            // 
            this.btn_boqua.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.btn_boqua.ForeColor = System.Drawing.Color.DarkBlue;
            this.btn_boqua.Image = global::Human.Properties.Resources.t_boqua1;
            this.btn_boqua.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
            this.btn_boqua.Location = new System.Drawing.Point(232, 20);
            this.btn_boqua.Name = "btn_boqua";
            this.btn_boqua.Size = new System.Drawing.Size(70, 28);
            this.btn_boqua.TabIndex = 10;
            this.btn_boqua.Text = "&Bỏ qua";
            this.btn_boqua.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            this.btn_boqua.UseVisualStyleBackColor = true;
            this.btn_boqua.Click += new System.EventHandler(this.btn_boqua_Click);
            // 
            // btn_luu
            // 
            this.btn_luu.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.btn_luu.ForeColor = System.Drawing.Color.DarkBlue;
            this.btn_luu.Image = global::Human.Properties.Resources.save;
            this.btn_luu.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
            this.btn_luu.Location = new System.Drawing.Point(166, 20);
            this.btn_luu.Name = "btn_luu";
            this.btn_luu.Size = new System.Drawing.Size(60, 28);
            this.btn_luu.TabIndex = 9;
            this.btn_luu.Text = "&Lưu";
            this.btn_luu.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            this.btn_luu.UseVisualStyleBackColor = true;
            this.btn_luu.Click += new System.EventHandler(this.btn_luu_Click);
            this.btn_luu.KeyDown += new System.Windows.Forms.KeyEventHandler(this.btn_luu_KeyDown);
            // 
            // btn_sua
            // 
            this.btn_sua.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.btn_sua.ForeColor = System.Drawing.Color.DarkBlue;
            this.btn_sua.Image = global::Human.Properties.Resources.quick_edit;
            this.btn_sua.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
            this.btn_sua.Location = new System.Drawing.Point(100, 20);
            this.btn_sua.Name = "btn_sua";
            this.btn_sua.Size = new System.Drawing.Size(60, 28);
            this.btn_sua.TabIndex = 8;
            this.btn_sua.Text = "&Sửa";
            this.btn_sua.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            this.btn_sua.UseVisualStyleBackColor = true;
            this.btn_sua.Click += new System.EventHandler(this.btn_sua_Click);
            this.btn_sua.KeyDown += new System.Windows.Forms.KeyEventHandler(this.btn_sua_KeyDown);
            // 
            // btn_them
            // 
            this.btn_them.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.btn_them.ForeColor = System.Drawing.Color.DarkBlue;
            this.btn_them.Image = global::Human.Properties.Resources.add;
            this.btn_them.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
            this.btn_them.Location = new System.Drawing.Point(34, 20);
            this.btn_them.Name = "btn_them";
            this.btn_them.Size = new System.Drawing.Size(60, 28);
            this.btn_them.TabIndex = 7;
            this.btn_them.Text = "&Thêm";
            this.btn_them.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            this.btn_them.UseVisualStyleBackColor = true;
            this.btn_them.Click += new System.EventHandler(this.btn_them_Click);
            this.btn_them.KeyDown += new System.Windows.Forms.KeyEventHandler(this.btn_them_KeyDown);
            // 
            // frmChucv
            // 
            this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
            this.ClientSize = new System.Drawing.Size(512, 423);
            this.Controls.Add(this.groupBox1);
            this.Controls.Add(this.checklanhdao);
            this.Controls.Add(this.label6);
            this.Controls.Add(this.label4);
            this.Controls.Add(this.txttenvt);
            this.Controls.Add(this.txtheso);
            this.Controls.Add(this.label5);
            this.Controls.Add(this.txtsott);
            this.Controls.Add(this.label3);
            this.Controls.Add(this.txtTen);
            this.Controls.Add(this.label2);
            this.Controls.Add(this.label1);
            this.Controls.Add(this.txtMa);
            this.Controls.Add(this.dgrDanhMuc1);
            this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
            this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
            this.MaximizeBox = false;
            this.MinimizeBox = false;
            this.Name = "frmChucv";
            this.ShowInTaskbar = false;
            this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
            this.Text = "Chức vụ";
            this.Load += new System.EventHandler(this.frmChucv_Load);
            ((System.ComponentModel.ISupportInitialize)(this.dgrDanhMuc1)).EndInit();
            this.groupBox1.ResumeLayout(false);
            this.ResumeLayout(false);
            this.PerformLayout();

		}
		#endregion

		private void frmChucv_Load(object sender, System.EventArgs e)
		{
			chucvu();
			Ena_control(true);
			refresh_Text();
			Ena_textbox(false);
			btn_them.Focus();
		}

		private void chucvu()
		{
			DataSet ds1=new DataSet();
			ds1=mDB.get_chucvu(); 
			dgrDanhMuc1.DataSource=null;
			dgrDanhMuc1.TableStyles.Clear();
			DataGridTableStyle ts = new DataGridTableStyle();
			ts.MappingName = ds1.Tables[0].TableName;
		
			ts.AlternatingBackColor = Color.Beige;
			ts.BackColor = Color.GhostWhite;
			ts.ForeColor = Color.MidnightBlue;
			ts.GridLineColor = Color.RoyalBlue;
			ts.HeaderBackColor = Color.MidnightBlue;
			ts.HeaderForeColor = Color.Lavender;
			ts.SelectionBackColor = Color.Teal;
			ts.SelectionForeColor = Color.PaleGreen;
			
			DataGridTextBoxColumn TextCol1=new DataGridTextBoxColumn();
			TextCol1.MappingName = "macv";
            TextCol1.HeaderText =lan.Change_language_MessageText("Mã CV");
			TextCol1.Width = 60;
			TextCol1.ReadOnly=true;
			TextCol1.Alignment=HorizontalAlignment.Left;
			ts.GridColumnStyles.Add(TextCol1);
			dgrDanhMuc1.TableStyles.Add(ts);
		
			DataGridTextBoxColumn TextCol2=new DataGridTextBoxColumn();
			TextCol2.MappingName = "diengiai";
			TextCol2.HeaderText = lan.Change_language_MessageText("Tên chức vụ");
			TextCol2.Width = 200;
			TextCol2.ReadOnly=true;
			TextCol2.Alignment=HorizontalAlignment.Left;
			ts.GridColumnStyles.Add(TextCol2);
			dgrDanhMuc1.TableStyles.Add(ts);

            DataGridTextBoxColumn TextCol3 = new DataGridTextBoxColumn();
            TextCol3.MappingName = "tenvt";
            TextCol3.HeaderText = lan.Change_language_MessageText("Tên viết tắt");
            TextCol3.Width = 60;
            TextCol3.ReadOnly = true;
            TextCol3.Alignment = HorizontalAlignment.Left;
            ts.GridColumnStyles.Add(TextCol3);
            dgrDanhMuc1.TableStyles.Add(ts);

            DataGridTextBoxColumn TextCol4 = new DataGridTextBoxColumn();
            TextCol4.MappingName = "hscv";
            TextCol4.HeaderText = lan.Change_language_MessageText("Hệ số CV");
            TextCol4.Width = 40;
            TextCol4.ReadOnly = true;
            TextCol4.Alignment = HorizontalAlignment.Left;
            ts.GridColumnStyles.Add(TextCol4);
            dgrDanhMuc1.TableStyles.Add(ts);

            DataGridTextBoxColumn TextCol5 = new DataGridTextBoxColumn();
            TextCol5.MappingName = "stt";
            TextCol5.HeaderText = lan.Change_language_MessageText("Số TT");
            TextCol5.Width = 40;
            TextCol5.ReadOnly = true;
            TextCol5.Alignment = HorizontalAlignment.Center;
            ts.GridColumnStyles.Add(TextCol5);
            dgrDanhMuc1.TableStyles.Add(ts);

            DataGridTextBoxColumn TextCol6 = new DataGridTextBoxColumn();
            TextCol6.MappingName = "lanhdao";
            TextCol6.HeaderText = lan.Change_language_MessageText("Lãnh đạo");
            TextCol6.Width = 40;
            TextCol6.ReadOnly = true;
            TextCol6.Alignment = HorizontalAlignment.Center;
            ts.GridColumnStyles.Add(TextCol6);
            dgrDanhMuc1.TableStyles.Add(ts);
		
			ts.DataGrid.DataSource=ds1.Tables[0]; 

			CurrencyManager cm = (CurrencyManager) BindingContext[dgrDanhMuc1.DataSource,dgrDanhMuc1.DataMember];
			DataView dv = (DataView) cm.List;
			dv.AllowNew=false;
			dv.AllowEdit=false;
			dv.AllowDelete=false;
		}	
		private void Ena_control(bool ena)
		{
			btn_them.Enabled=ena;
			btn_sua.Enabled=ena;
			btn_luu.Enabled=!ena;
			btn_boqua.Enabled=!ena;
			btn_xoa.Enabled=ena;
			btn_thoat.Enabled=ena;
		}

		private void Ena_textbox(bool ena)
		{
            txtsott.Enabled = ena;
            txtTen.Enabled=ena;
            txtheso.Enabled = ena;
            txttenvt.Enabled = ena;
            checklanhdao.Enabled = ena;
		}

		private void clear_Text()
		{			
			txtTen.Clear();
            txtMa.Text = "";
            
		}

		private void refresh_Text()
		{
			int i=dgrDanhMuc1.CurrentRowIndex;
			if(i>=0)
			{
				txtMa.Text=dgrDanhMuc1[i,0].ToString();
				txtTen.Text=dgrDanhMuc1[i,1].ToString();
                txttenvt.Text = dgrDanhMuc1[i, 2].ToString();
                txtheso.Text = dgrDanhMuc1[i, 3].ToString();
                txtsott.Text = dgrDanhMuc1[i, 4].ToString();
                checklanhdao.Checked = Convert.ToBoolean(dgrDanhMuc1[i, 5].ToString());
			}
		}		
		private void btnKetthuc_Click(object sender, System.EventArgs e)
		{
			this.Close();
		}

		private void dgrDanhMuc1_CurrentCellChanged(object sender, System.EventArgs e)
		{
			try
			{
				refresh_Text();
				Ena_textbox(false);
				Ena_control(true);
			}
			catch{}
		}

		private void txtTen_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
		{
			if(e.KeyCode==Keys.Enter)
			{
                SendKeys.Send("{Tab}");
			}
		}

        private bool kemtra(string macv)
        {
            bool flag = false;
            string t=mDB.get_data("select count(*) as tong from " + mDB.user + ".hopdong where macv='" + macv + "'").Tables[0].Rows[0][0].ToString();
            try
            {
                if (Convert.ToInt32(t) > 0)
                {
                    flag = true;
                }
                else
                {
                    flag = false;
                }
            }
            catch
            {
                flag = false;
            }
            if (flag)
                MessageBox.Show(lan.Change_language_MessageText("Chức vụ đã sử dụng không thể hủy!"),AccessData.Msg);
            return flag;            
            
        }

        private void txtMa_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
                SendKeys.Send("{Tab}");
        }

        private void txttenvt_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
                SendKeys.Send("{Tab}");
        }

        private void txtsott_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
                SendKeys.Send("{Tab}");
        }

        private void txtheso_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
                SendKeys.Send("{Tab}");
        }

        private void checklanhdao_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
                btn_luu.Focus();
        }
        private string get_maxid()
        {
            int m_tam = 0;
            ds = mDB.get_data("SELECT Max(to_number(macv,999)) FROM " + mDB.user + ".dmcv");
            if(ds.Tables[0].Rows.Count > 0)
                m_tam = ds.Tables[0].Rows[0][0].ToString() !="" ? int.Parse(ds.Tables[0].Rows[0][0].ToString()) + 1:1;
            else
                m_tam = 1;
          return m_tam.ToString().PadLeft(3, '0').ToString();
        }
        private void btn_them_Click(object sender, EventArgs e)
        {
            Ena_control(false);
            Ena_textbox(true);
            clear_Text();
            m_user = mDB.user;
            txtMa.Text = get_maxid();
            flag = 0;
            txtTen.Focus();
        }

        private void btn_sua_Click(object sender, EventArgs e)
        {
            flag = 1;
            Ena_control(false);
            Ena_textbox(true);
            txtTen.Focus();
        }

        private void btn_luu_Click(object sender, EventArgs e)
        {
            try
            {
                string macv = "", ten = "", tenvt = "";
                int m_id = 0;
                decimal heso = 0, stt = 0;
                bool lanhdao;
                macv = txtMa.Text.Trim();
                ten = txtTen.Text.Trim();
                tenvt = txttenvt.Text.Trim();
                stt = txtsott.Text.Trim()!="" ? decimal.Parse(txtsott.Text.Trim()):0;
                heso =txtheso.Text.Trim()!="" ? decimal.Parse(txtheso.Text.Trim()):0;
                lanhdao = checklanhdao.Checked;
                if (flag == 0)
                {
                    m_id = Int32.Parse(get_maxid());
                    txtMa.Text = m_id.ToString().PadLeft(3, '0');
                }
                else
                {
                    if (txtMa.Text != "")
                        m_id = Int32.Parse(txtMa.Text.ToString());
                }
                mDB.Insert_DMCHUCVU(macv, ten, tenvt, stt, heso, lanhdao);
                chucvu();
                flag = 0;
                mDB.upd_hscv(macv, heso);
                Ena_control(true);
                Ena_textbox(false);
            }
            catch { }
        }

        private void btn_boqua_Click(object sender, EventArgs e)
        {
            Ena_control(true);
            Ena_textbox(false);
            refresh_Text();
            btn_thoat.Focus();
        }

        private void btn_xoa_Click(object sender, EventArgs e)
        {
            try
            {
                int i = dgrDanhMuc1.CurrentCell.RowNumber;
                if (i < 0)
                    i = dgrDanhMuc1.CurrentCell.RowNumber;
                if (i == dgrDanhMuc1.CurrentCell.RowNumber)
                {
                    DialogResult dr = MessageBox.Show(lan.Change_language_MessageText("Đồng ý huỷ chức vụ này?"),AccessData.Msg, MessageBoxButtons.YesNo);
                    if (dr == DialogResult.Yes && !kemtra(txtMa.Text.Trim()))
                    {
                        mDB.get_data("DELETE  FROM " + mDB.user + ".dmcv WHERE macv='" + txtMa.Text.Trim() + "'");
                    }
                    chucvu();
                    refresh_Text();
                }
            }
            catch { }
        }

        private void btn_thoat_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void btn_luu_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
                btn_them.Focus();
        }

        private void btn_them_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
                txtTen.Focus();
        }

        private void btn_sua_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
                txtTen.Focus();
        }
	}
}
